/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2017
 */

package com.shop.pandian.app.model;

import java.util.List;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotBlank;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.shop.pandian.framework.base.dao.BaseUpdatableEntity;
import com.shop.pandian.util.ConvertUtils;

/**
 * @author Xi Wei
 * @version 1.0
 * @since 1.0
 */
 @Entity
@Table(name = "acct_role")
public class AcctRole extends BaseUpdatableEntity implements java.io.Serializable{
	private static final long serialVersionUID = 5454155825314635342L;

	


	//可以直接使用: @Length(max=50,message="用户名长度不能大于50")显示错误消息
	//columns START
	@NotBlank @Length(max=45)
	
	@Column(name = "role_code", unique = true, nullable = false, insertable = true, updatable = true, length = 45)
	private java.lang.String roleCode; //roleCode
	@NotBlank @Length(max=250)
	
	@Column(name = "role_name", unique = false, nullable = false, insertable = true, updatable = true, length = 250)
	private java.lang.String roleName; //roleName
	@Length(max=250)
	
	@Column(name = "role_desc", unique = false, nullable = true, insertable = true, updatable = true, length = 250)
	private java.lang.String roleDesc; //roleDesc
	
	
	//columns END



	
	
	
	public java.lang.String getRoleCode() {
		return this.roleCode;
	}
	
	public void setRoleCode(java.lang.String value) {
		this.roleCode = value;
	}

	public java.lang.String getRoleName() {
		return this.roleName;
	}
	
	public void setRoleName(java.lang.String value) {
		this.roleName = value;
	}

	public java.lang.String getRoleDesc() {
		return this.roleDesc;
	}
	
	public void setRoleDesc(java.lang.String value) {
		this.roleDesc = value;
	}


	@JsonIgnore
	@ManyToMany(fetch = FetchType.LAZY)
	@Fetch(FetchMode.SUBSELECT)
	@JoinTable(name = "acct_role_authority", joinColumns = { @JoinColumn(name = "ROLE_ID") }, inverseJoinColumns = { @JoinColumn(name = "AUTHORITY_ID") })
	private Set<AcctAuthority> authorityList = Sets.newHashSet();
	public Set<AcctAuthority> getAuthorityList() {
		return this.authorityList;
	}

	public void setAuthorityList(Set<AcctAuthority> authorityList) {
		this.authorityList = authorityList;
	}
	
	
	@Transient
	private String authorityNames;

	public String getAuthorityNames() {
		return ConvertUtils.convertElementPropertyToString(getAuthorityList(), "authName", ",");
	}

}

